﻿/******************************************************************************
 * 
 * Announce: CSharpKit, Basic algorithms, components and definitions.
 *           Copyright (C) ShenYongchen.
 *           All rights reserved.
 *   Author: 申永辰.郑州 (shenyczz@163.com)
 *  WebSite: http://gitee.com/shenyczz/csharp_csk
 *
 * THIS CODE IS LICENSED UNDER THE MIT LICENSE (MIT).
 * THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF 
 * ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
 * IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
 * PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 * 
******************************************************************************/
using System;
using System.Runtime.InteropServices;

using codes_handle = System.IntPtr;
using codes_nearest = System.IntPtr;

namespace CSharpKit.Native.ECCODES
{
    partial class eccodes
    {
        /// <summary>
        /// <para>功能: Create a new nearest neighbour object from a handle, using current geometry. </para>
        /// <para>说明: </para>
        /// </summary>
        /// <param name="handle"> the handle from which the nearest object will be created </param>
        /// <param name="err"> error code </param>
        /// <returns> the new nearest, NULL if no nearest can be created </returns>
        /// <remarks>
        /// 原型: codes_nearest* codes_grib_nearest_new(const codes_handle* h, int* error)
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_grib_nearest_new")]
        public static extern codes_nearest codes_grib_nearest_new(codes_handle handle, out int err);


        /**
        * 
        *
        * @param nearest     : 
        * @param h           : 
        * @param inlat       :
        * @param inlon       :
        * @param flags       : 
        * @param outlats     : 
        * @param outlons     : 
        * @param values      : 
        * @param distances   : 
        * @param indexes     : 
        * @param len         : 
        * @return            
*/
        /// <summary>
        /// <para>功能: Find the 4 nearest points of a latitude longitude point. </para>
        /// <para>说明: 
        /// The flags are provided to speed up the process of searching. If you are
        /// sure that the point you are asking for is not changing from a call
        /// to another you can use CODES_NEAREST_SAME_POINT. The same is valid for
        /// the grid. Flags can be used together doing a bitwise OR.
        /// The distances are given in kilometres.
        /// </para>
        /// </summary>
        /// <param name="nearest"> nearest structure </param>
        /// <param name="handle"> handle from which geography and data values are taken</param>
        /// <param name="inlat"> latitude of the point to search for </param>
        /// <param name="inlon"> longitude of the point to search for </param>
        /// <param name="flags"> CODES_NEAREST_SAME_POINT, CODES_NEAREST_SAME_GRID </param>
        /// <param name="outlats"> returned array of latitudes of the nearest points</param>
        /// <param name="outlons"> returned array of longitudes of the nearest points </param>
        /// <param name="values">returned array of data values of the nearest points </param>
        /// <param name="distances">returned array of distances from the nearest points</param>
        /// <param name="indexes">returned array of indexes of the nearest points</param>
        /// <param name="len">size of the arrays</param>
        /// <returns> 0 if OK, integer value on error </returns>
        /// <remarks>
        /// 原型: int codes_grib_nearest_find(codes_nearest* nearest, const codes_handle* h, double inlat, double inlon,
        ///                                   unsigned long flags, double* outlats, double* outlons,
        ///                                   double* values, double* distances, int* indexes, size_t* len);
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_grib_nearest_find")]
        public static extern int codes_grib_nearest_find(
            codes_nearest nearest, codes_handle handle,
            in double inlat, in double inlon, ulong flags,
            out double[] outlats, out double[] outlons, out double[] values,
            out double[] distances, out int[] indexes, out int len);



        /// <summary>
        /// <para>功能: Frees an nearest from memory </para>
        /// <para>说明: </para>
        /// </summary>
        /// <param name="nearest"> the nearest </param>
        /// <returns> 0 if OK, integer value on error </returns>
        /// <remarks>
        /// 原型: int codes_grib_nearest_delete(codes_nearest* nearest)
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_grib_nearest_delete")]
        public static extern int codes_grib_nearest_delete(codes_nearest nearest);



        /**
        * 
        *
        * @param h           :
        * @param is_lsm      : 
        * @param inlats      : 
        * @param inlons      : 
        * @param npoints     : 
        * @param outlats     : 
        * @param outlons     : 
        * @param values      : 
        * @param distances   : 
        * @param indexes     : 
        * @return            
*/
        /// <summary>
        /// <para>功能: Find the nearest point of a set of points whose latitudes and longitudes are given in the inlats, inlons arrays respectively. </para>
        /// <para>说明: 
        /// If the flag is_lsm is 1 the nearest land point is returned and the
        /// GRIB passed as handle (h) is considered a land sea mask.
        /// The land nearest point is the nearest point with land sea mask value>=0.5.
        /// If no nearest land points are found the nearest value is returned.
        /// If the flag is_lsm is 0 the nearest point is returned.
        /// values, distances, indexes (in the "values" array) for the nearest points (ilons,ilats)
        /// are returned.
        /// The distances are given in kilometres.
        /// </para>
        /// </summary>
        /// <param name="handle">handle from which geography and data values are taken </param>
        /// <param name="is_lsm">lsm flag (1-> nearest land, 0-> nearest) </param>
        /// <param name="inlats">latitudes of the points to search for</param>
        /// <param name="inlons">longitudes of the points to search for </param>
        /// <param name="npoints">number of points (size of the inlats,inlons,outlats,outlons,values,distances,indexes arrays) </param>
        /// <param name="outlats">returned array of latitudes of the nearest points </param>
        /// <param name="outlons">returned array of longitudes of the nearest points </param>
        /// <param name="values">returned array of data values of the nearest points </param>
        /// <param name="distances">returned array of distances from the nearest points </param>
        /// <param name="indexes">returned array of indexes of the nearest points </param>
        /// <returns>0 if OK, integer value on error </returns>
        /// <remarks>
        /// 原型: int codes_grib_nearest_find_multiple(const codes_handle* h, int is_lsm,
        ///                                    const double* inlats, const double* inlons, long npoints,
        ///                                    double* outlats, double* outlons,
        ///                                    double* values, double* distances, int* indexes);
        /// </remarks>
        [DllImport(_dllname_, CharSet = CharSet.Auto, EntryPoint = "codes_grib_nearest_find_multiple")]
        public static extern int codes_grib_nearest_find_multiple(
            codes_handle handle, int is_lsm, in double[] inlats, in double[] inlons, long npoints,
            out double[] outlats, out double[] outlons, out double[] values, out double distances, out int[] indexes
        );


        // {{END}}
    }
}
